package com.jgp.security.shiro.filter;

import com.jgp.common.type.EndPointType;
import com.jgp.security.shiro.pojo.JgpUsernamePasswordToken;
import lombok.extern.log4j.Log4j2;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2019/1/24
 */
@Log4j2
public class MobileAuthenticationFilter extends FormAuthenticationFilter {
    private static final Logger logger = LoggerFactory.getLogger(NormalAuthenticationFilter.class);
    
    public MobileAuthenticationFilter(){
        this.setLoginUrl("/security/entry-ctl/mobile-login");
        this.setUsernameParam("admin_name");
        this.setPasswordParam("admin_pwd");
        this.setRememberMeParam("admin_remember_me");
    }
    
    @Override
    protected boolean isLoginSubmission(ServletRequest request, ServletResponse response) {
        return super.isLoginSubmission(request, response);
    }
    
    @Override
    protected AuthenticationToken createToken(String username, String password,
                                              boolean rememberMe, String host) {
        return new JgpUsernamePasswordToken(username, password, rememberMe, host, EndPointType.PC);
    }
}
